<?php
namespace App\Http\Controllers;

use App\Http\Controllers\WebController;
use App\Http\Controllers\Business\WaterModule;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Facades\Excel;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\File;
use App\Models\Position;
use App\Models\WaterMeterDayConsumption;
use App\Models\WaterMeter;

class TestController extends WebController
{
    public function test() {
        return view('test1');
    }
    public function addPosition() {
        $address = $this->request->get('address');
        $position = $this->request->get('position');
        if($address) {
            Position::create([
                'address' => $address,
                'position' => $position
            ]);
        }
    }
    public function addWaterMeterDayConsumption() {
        $waterMeterLists = WaterMeter::where('number', '<>', 'ch00')->get();
        foreach($waterMeterLists as $waterMeterList) {
            $number = $waterMeterList['number'];
            $radix = $waterMeterList['radix'];
            $lastRadix = $waterMeterList['last_radix'];
            $updatedAt = $waterMeterList['updated_at'];
            $consumption = bcsub($radix, $lastRadix, 2);
            WaterMeterDayConsumption::create([
                'number' => $number,
                'consumption' => $consumption,
                'current_date' => date('Y-m-d', strtotime($updatedAt))
            ]);
        }
    }
}